<?php 
class Exam_View_Helper_Question extends Zend_View_Helper_Abstract{
    protected $_exam_id = 0;
    protected $_exam = null;
    protected $_questions = null;
    protected $_answers = null;
    protected $_viewExplain = false;
    protected $_viewCorrectAnswer = false;
    protected $_viewStaticAnswer = false;
    protected $_content = null;
    protected $_currentQuestionNo = 0;
    protected $_staticLabel = array('a','b','c','d','e','f');
    protected $_useanswerquestion = null;
    protected $_answerlabel = array();
    protected $_isShowAnswer = true;
    protected $_usesmyQuestion = false;
    protected $_isReadOnlyAnswer = false;
    protected $_type = 1;
    protected $_numberQuestionPerPage = 10;
    protected $_finishTest = false;
    protected $_useThisQuestion = true;
    
    public function question(){
        $this->view->labelAction = array(
            'hiddenAnswer'=>$this->view->translate('Hidden Answer'),
            'showAnswere' =>$this->view->translate('Show answer')
            
        );
        $this->view->isViewAnswer = $this->_isShowAnswer;
        return $this;
    }
    public function setExam($exam){
        if(is_numeric($exam)){
            $this->_exam_id = $exam;
            
        }
        if($exam instanceof Exam_Model_Exam){
            $this->_exam = $exam;
            $this->_exam_id = $exam['exam_id'];
        }
        
    }
    
    public function setFinishTest($value){
        $this->_finishTest = $value;
    }
    public function setReadOnlyAnswer($value){
        $this->_isReadOnlyAnswer = $value;
    }
    public function setUseMyQuestion($value){
        $this->_usesmyQuestion = $value;
    }
    public function setIsShowAnswer($value){
        $this->_isShowAnswer = $value;
    }
    
    public function setUserAnswerQuestion($values){
        $this->_useanswerquestion = $values;
    }
    public function setQuestions($questions ){
        if(is_numeric($questions)) {
            $questions = array(Engine_Api::_()->getItem('exam_question',$questions));
        }
        if(is_array($questions) && is_numeric($questions[0])){
            $questions = Engine_Api::_()->getItemMulti('exam_question',$questions);
        }
        $this->_questions = array();
        foreach($questions as $question){
            $questions[$question->question_id] = $question;
        }
    }
    
    public function setAnswers($answers){
        if(is_numeric($answers)) {
            $answers = array(Engine_Api::_()->getItem('exam_answer',$answers));
        }
        if(is_array($answers) && is_numeric($answers[0])){
            $answers = Engine_Api::_()->getItemMulti('exam_answer',$answers);
        }
        $this->_answers = array();
        foreach($answers as $answer){
            if(!isset($this->_answers[$answer->question_id])) $this->_answers[$answer->question_id] = array();
            $this->_answers[$answer->question_id] = $answer;
        }
    }
    
    public function setViewExplain($value){
        $this->_viewExplain = $value;
    }
    public function setViewStaticAnswer($value){
        $this->_viewStaticAnswer = $value;
    }
    public function setViewCorrectAnswer($value){
        $this->_viewCorrectAnswer = $value;
    }
    
    public function render(){
        $this->renderJavascript();
        $this->preProcess();

        $content = '';
        $this->_currentQuestionNo = 1;
        foreach($this->_questions as $question_id => $question){
            $content .= $this->renderQuestion($question);
            $this->_currentQuestionNo++;
        }
        return $content;
    }
    
    
    public function preProcess(){
        if(empty($this->_questions) || is_null($this->_questions)){
            $examdetailTable = Engine_Api::_()->getDbtable('examdetails','exam');
            $questions =  $examdetailTable->getListQuestion($this->_exam_id);
            $this->_questions = $questions;
            
            $question_ids = array();
            foreach($this->_questions as $item){
                $question_ids[] = $item->question_id;
            }
            $answerTable = Engine_Api::_()->getDbtable('answers','exam');
            $answers =  $answerTable->getAnswersByQuestions($question_ids,$this->_viewStaticAnswer,$this->_exam_id);
            $this->_answers = $answers;
           
            
        }
        if(empty($this->_answers) || is_null($this->_answers) && $this->_isShowAnswer){
            $question_ids = array();
            foreach($this->_questions as $item){
                $question_ids[] = $item->question_id;
            }
            $answerTable = Engine_Api::_()->getDbtable('answers','exam');
            $answers =  $answerTable->getAnswersByQuestions($question_ids,$this->_viewStaticAnswer,$this->_exam_id);
            $this->_answers = $answers;
        }
        
        
    }
    public function renderQuestion($question){
        $useQuestionUrl = 'sfsdf';
        $content = '';
        $content .= "<ul class='exam_question_content' id = 'exam_question_content_".$question['question_id']."' >";
        $content .= "<li class='exam_question_content_question' id = 'exam_question_content_question".$question['question_id']."'>";
        $content .= "<div class='exam_question_content_question_no' id='exam_question_content_question_no_".$question['question_id']."'>" .$this->_currentQuestionNo."</div>";
        $content .= "<div class='exam_question_content_question_content' id ='exam_question_content_question_content_".$question['question_id']."'>";
        $content .= $question['content']."</div>";
        $content .= "<div class='exam_question_content_question_result' id ='exam_question_content_question_result".$question['question_id']."'>";
        if($this->_useanswerquestion){
            if($question->number_choice == 1){
                $useselected = $this->_useanswerquestion[$question->question_id];
                $resulselected = $this->_answers[$question->question_id]['correct'];
                $diff =  array_diff($useselected,$resulselected);
                if(empty($diff)){
                    $content .=  $this->view->htmlImage($this->view->baseUrl() . '/application/modules/Exam/externals/images/correct.gif', $this->view->translate("Correct"), array('title' => $this->view->translate("Correct")));
                }
                else {
                    $content .=  $this->view->htmlImage($this->view->baseUrl() . '/application/modules/Exam/externals/images/incorrect.gif', $this->view->translate("Incorrect"), array('title' => $this->view->translate("InCorrect")));
                }
            }
            else {
                $useselected = $this->_useanswerquestion[$question->question_id];
                $resulselected = $this->_answers[$question->question_id]['correct'];
                $diff =  array_diff($useselected,$resulselected);
                if(empty($diff)){
                    $content .=  $this->view->htmlImage($this->view->baseUrl() . '/application/modules/Exam/externals/images/correct.gif', $this->view->translate("Correct"), array('title' => $this->view->translate("Correct")));
                }
                else {
                    $content .=  $this->view->htmlImage($this->view->baseUrl() . '/application/modules/Exam/externals/images/incorrect.gif', $this->view->translate("Incorrect"), array('title' => $this->view->translate("InCorrect")));
                }
            }
        }
        
        $content .='</div>';
        $content .="<div class='exam_question_content_question_action' id ='exam_question_contend_question_action".$question['question_id']."'>";
        if($this->_isShowAnswer){
            $content .= "<a href='javascript:void(0)' onclick = 'exam.test.toggleQuestion(this);' > ".$this->view->translate('Hidden answer')."</a>";
            if($this->_useThisQuestion){
                $content .= "<a href ='".$useQuestionUrl."' class = 'button_link smoothbox use_my' >".$this->view->translate('User my')."</a>";
            } 
        }
        else {
            $content .= "<a href='javascript:void(0)' onclick = 'exam.test.toggleQuestion(this);' > ".$this->view->translate('Show answer')."</a>";
            $content .= "<a href ='".$useQuestionUrl."' class = 'button_link smoothbox use_my' >".$this->view->translate('User my')."</a>"; 
        }

        $content .= "<a href ='". $this->view->Url(array('controller' => 'question', 'action' => 'edit','exam_id' => $this->_exam_id, 'question_id' => $question->question_id), 'exam_extended') ."' class = 'buttonlink smoothbox edit_questions' >".$this->view->translate('Edit')."</a>";
        
        $content .="</div>";  
        $content .='</li>';
        $content .= $this->renderAnswer($this->_answers[$question->question_id]['result'],$question,$question->number_choice,$this->_viewStaticAnswer,$this->_viewCorrectAnswer,$this->_viewExplain);
        $content .='</ul>';
        return $content;
    }
    public function renderAnswer($answer,$question,$number_choice = 1,$viewstatic=false,$viewanswer = false,$explain = true){
        $content = '<li class ="exam_question_content_answer" id="exam_question_content_answer'.$question['question_id'].'">';
        $multichoice = '';
        $group = null;
        $i = 0;
        $this->_answerlabel = array();
        $readonly = '';
        if($this->_isReadOnlyAnswer){
            $readonly = ' disabled="disabled" ';
        }
        // show list answer when user in test
        if($viewstatic == false && $viewanswer == false && $explain == false){
            $trueanswerids = $this->_answers[$question['question_id']]['correct'];
            foreach($answer as $item){
                $this->_answerlabel[$item['answer_id']] = $this->_staticLabel[$i];
                $content .='<div class="exam_question_content_answer_choice" id ="exam_question_content_answer_choice_'.$item['answer_id'].'" >';
                if($number_choice == 1) {
                    $select = "";
                    if( $this->_useanswerquestion && in_array($item['answer_id'],$this->_useanswerquestion[$question['question_id']])) $select =" checked ='checked' ";
                    $content .= '<input '.$readonly.' '.$select.' selected = "selected" type = "radio" name = "radio_'.$question['question_id'].'" value = "'.$item['answer_id'].'">';
                    $content .= '<label for="radio_'.$question['question_id'].'" > <b>'.$this->_staticLabel[$i].'</b> ' .$item['content'] .'</label>';
                }
                else{
                    $select = "";
                    if($this->_useanswerquestion && in_array($item['answer_id'],$this->_useanswerquestion[$question['question_id']])) $select =" checked ='checked' ";
                    $content .= '<input '.$readonly.' '.$select.' type = "checkbox" name = "checkbox_'.$question['question_id'].'[]" value = "'.$item['answer_id'].'">';
                    $content .= '<label for="checkbox_'.$question['question_id'].'" > <b>'.$this->_staticLabel[$i].'</b> ' .$item['content'] .'</label>';
                    if( in_array($item['answer_id'],$trueanswerids)) $multichoice .= $this->_staticLabel[$i]. ',';
                }
                $content .='</div>';
                $i++;
            }
        }
        else if($viewstatic == true && $viewanswer == false && $explain == false){
            $trueanswerids = $this->_answers[$question['question_id']]['correct'];
            $group = $this->_answers[$question['question_id']]['group'];
            foreach($answer as $item){
                $this->_answerlabel[$item['answer_id']] = $this->_staticLabel[$i];
                $content .='<div class="exam_question_content_answer_choice" id ="exam_question_content_answer_choice_'.$item['answer_id'].'" >';
                $content .='<div class="exam_question_content_answer_choice_answer" id="exam_question_content_answer_choice_answer_'.$item['answer_id'].'">';
                if($number_choice == 1) {
                    $select = "";
                    if( $this->_useanswerquestion && in_array($item['answer_id'],$this->_useanswerquestion[$question['question_id']])) $select =" checked ='checked' ";
                    $content .= '<input '.$readonly.' '.$select.' type = "radio" name = "radio_'.$question['question_id'].'" value = "'.$item['answer_id'].'">';
                    $content .= '<label for="radio_'.$question['question_id'].'" > <b>'.$this->_staticLabel[$i].'</b> ' .$item['content'] .'</label>';
                }
                else{
                    $select = "";
                    if($this->_useanswerquestion && in_array($item['answer_id'],$this->_useanswerquestion[$question['question_id']])) $select =" checked ='checked' ";
                    $content .= '<input  '.$readonly.' '.$select.' type = "checkbox" name = "checkbox_'.$question['question_id'].'[]" value = "'.$item['answer_id'].'">';
                    $content .= '<label for="checkbox_'.$question['question_id'].'" > <b>'.$this->_staticLabel[$i].'</b> ' .$item['content'] .'</label>';
                    if( in_array($item['answer_id'],$trueanswerids)) $multichoice .= $this->_staticLabel[$i]. ',';
                }
                $content .='</div>';
                if($number_choice== 1){
                    $percent = $this->_answers[$question['question_id']]['group'][$item['answer_id'].','] / $this->_exam->test_count;
                    $percent = $percent * 100;
                    $content .='<div class="exam_question_content_answer_choice_result" id="exam_question_content_answer_choice_result_'.$item['answer_id'].'">';
                    $content .= $this->view->htmlImage($this->view->baseUrl() . '/application/modules/Exam/externals/images/percent.gif', '', array('title' => $this->view->translate(""),'width'=>round($percent).'px;','height'=>'20px;'));
                    $content .='<span class="exam_question_content_answer_choice_result_percent_label">'.round($percent,2).'%</span>';
                    $content .='</div>';
                }
                $content .='</div>';
                
                $i++;
            }
        }
        else if($viewstatic == true && $viewanswer == true && $explain == false) {
            $trueanswerids = $this->_answers[$question['question_id']]['correct'];
            $group = $this->_answers[$question['question_id']]['group'];
            foreach($answer as $item){
                $this->_answerlabel[$item['answer_id']] = $this->_staticLabel[$i];
                $correctClass = 'answer_incorrect';
                if($item['result']== true) $correctClass = 'answer_correct';
                $content .='<div class="exam_question_content_answer_choice" id ="exam_question_content_answer_choice_'.$item['answer_id'].'" >';
                $content .='<div class="exam_question_content_answer_choice_answer" id="exam_question_content_answer_choice_answer_'.$item['answer_id'].'">';
                if($number_choice == 1) {
                    $select = "";
                    if( $this->_useanswerquestion && in_array($item['answer_id'],$this->_useanswerquestion[$question['question_id']])) $select =" checked ='checked' ";
                    $content .= '<input  '.$readonly.' '.$select.' type = "radio" name = "radio_'.$question['question_id'].'" value = "'.$item['answer_id'].'">';
                    $content .= '<label for="radio_'.$question['question_id'].'" > <b>'.$this->_staticLabel[$i].'</b> ' .$item['content'] .'</label>';
                }
                else{
                    $select = "";
                    if($this->_useanswerquestion && in_array($item['answer_id'],$this->_useanswerquestion[$question['question_id']])) $select =" checked ='checked' ";
                    $content .= '<input '.$readonly.' '.$select.' type = "checkbox" name = "checkbox_'.$question['question_id'].'[]" value = "'.$item['answer_id'].'">';
                    $content .= '<label for="checkbox_'.$question['question_id'].'" > <b>'.$this->_staticLabel[$i].'</b> ' .$item['content'] .'</label>';
                    if( in_array($item['answer_id'],$trueanswerids)) $multichoice .= $this->_staticLabel[$i]. ',';
                }
                $content .='</div>';
                if($number_choice== 1){
                    $percent = $this->_answers[$question['question_id']]['group'][$item['answer_id'].','] / $this->_exam->test_count;
                    $percent = $percent * 100;
                    $content .='<div class="exam_question_content_answer_choice_result" id="exam_question_content_answer_choice_result_'.$item['answer_id'].'">';
                    $content .= $this->view->htmlImage($this->view->baseUrl() . '/application/modules/Exam/externals/images/'.$correctClass.'.gif', '', array('title' => $this->view->translate(""),'width'=>round($percent).'px;','height'=>'20px;'));
                    $content .='<span class="exam_question_content_answer_choice_result_percent_label">'.round($percent,2).'%</span>';
                    $content .='</div>';
                }
                
                
                $content .='</div>';
                $i++;
            }
            
        }
        else if($viewstatic == true && $viewanswer == true && $explain == true){
            $trueanswerids = $this->_answers[$question['question_id']]['correct'];
            $group = $this->_answers[$question['question_id']]['group'];
            foreach($answer as $item){
                $this->_answerlabel[$item['answer_id']] = $this->_staticLabel[$i];
                $correctClass = 'answer_incorrect';
                if($item['result']== true) $correctClass = 'answer_correct';
                $content .='<div class="exam_question_content_answer_choice" id ="exam_question_content_answer_choice_'.$item['answer_id'].'" >';
                $content .='<div class="exam_question_content_answer_choice_answer" id="exam_question_content_answer_choice_answer_'.$item['answer_id'].'">';
                if($number_choice == 1) {
                    $select = "";
                    if( $this->_useanswerquestion && in_array($item['answer_id'],$this->_useanswerquestion[$question['question_id']])) $select =" checked ='checked' ";
                    $content .= '<input '.$readonly.' '.$select.' type = "radio" name = "radio_'.$question['question_id'].'" value = "'.$item['answer_id'].'">';
                    $content .= '<label for="radio_'.$question['question_id'].'" > <b>'.$this->_staticLabel[$i].'</b> ' .$item['content'] .'</label>';
                }
                else{
                    $select = "";
                    if($this->_useanswerquestion && in_array($item['answer_id'],$this->_useanswerquestion[$question['question_id']])) $select =" checked ='checked' ";
                    $content .= '<input '.$readonly.' '.$select.' type = "checkbox" name = "checkbox_'.$question['question_id'].'[]" value = "'.$item['answer_id'].'">';
                    $content .= '<label for="checkbox_'.$question['question_id'].'" > <b>'.$this->_staticLabel[$i].'</b> ' .$item['content'] .'</label>';
                    if( in_array($item['answer_id'],$trueanswerids)) $multichoice .= $this->_staticLabel[$i]. ',';
                }
                $content .='</div>';
                
                if($number_choice == 1){
                    $percent = $this->_answers[$question['question_id']]['group'][$item['answer_id'].','] / $this->_exam->test_count;
                    $percent = $percent * 100;
                    $content .='<div class="exam_question_content_answer_choice_result" id="exam_question_content_answer_choice_result_'.$item['answer_id'].'">';
                    $content .= $this->view->htmlImage($this->view->baseUrl() . '/application/modules/Exam/externals/images/'.$correctClass.'.gif','', array('title' => $this->view->translate(""),'width'=>round($percent).'px;','height'=>'20px;'));
                    $content .='<span class="exam_question_content_answer_choice_result_percent_label">'.round($percent,2).'%</span>';
                    $content .='</div>';
                }
                $content .='<div class="exam_question_content_answer_choice_explain" id="exam_question_content_answer_choice_explain_'.$item['answer_id'].'">';
                $content .= '<a href="javascript:void(0)" class="smoothbox"> view explain</a> ' ;
                $content .='</div>';
                
                
                
                $content .='</div>';
                $i++;
               
            }
            
        }
        $content .='</li>';
        if($viewstatic == true && $viewanswer == false && $explain == false && $number_choice != 1){
                $multichoice = substr($multichoice,0,-1);
                $content .='<li class ="exam_question_content_answer_mulichoice">';
                $content .= '<div class="exam_question_content_answer_mulichoice_result" id="exam_question_content_answer_mulichoice_result_'.$item['answer_id'].'">';
                
                foreach($group as $key=> $value){
                    $label = $this->getlabel($key,$this->_answerlabel);
                    $value = $value / $this->_exam->test_count;
                    $value = $value *100;
                    $content .= '<div class="exam_question_content_answer_mulichoice_result_incorrect" id="exam_question_content_answer_mulichoice_result_'.$item['answer_id'].'">';
                    $content .= '<b>'.$label.'</b></div>';
                    $content .='<div class="exam_question_content_answer_mulichoice_percent_incorrect" id="exam_question_content_answer_mulichoice_percent_'.$item['answer_id'].'">';
                    $content .= $this->view->htmlImage($this->view->baseUrl(). '/application/modules/Exam/externals/images/answer_incorrect.gif', '', array('title' => $this->view->translate(""),"width"=>round($value).'px;','height'=>'20px;'));
                    $content .= '<span class="exam_question_content_answer_mulichoice_percent_incorrect_label">'.round($value,2).'%</span>';
                    $content .='</div>';
                }
                $content .= '</div>';
                $content .='</li>';
                
        }
        if($viewstatic == true && $viewanswer == true && $explain == false && $number_choice != 1){
                $multichoice = substr($multichoice,0,-1);
                $value = $this->getKey($multichoice,$this->_answerlabel);
                $percent = $group[$value] / $this->_exam->test_count;
                $percent = $percent * 100;
                
                $content .='<li class ="exam_question_content_answer_mulichoice">';
                $content .= '<div class="exam_question_content_answer_mulichoice_result" id="exam_question_content_answer_mulichoice_result_'.$item['answer_id'].'">';
                $content .= '<div class="exam_question_content_answer_mulichoice_result_correct" id="exam_question_content_answer_mulichoice_result_'.$item['answer_id'].'">';
                $content .= '<b>'.$multichoice.'</b></div>';
                $content .='<div class="exam_question_content_answer_mulichoice_percent_correct" id="exam_question_content_answer_mulichoice_percent_'.$item['answer_id'].'">';
                $content .= $this->view->htmlImage($this->view->baseUrl() . '/application/modules/Exam/externals/images/answer_correct.gif','', array('title' => $this->view->translate(""),"width"=>round($percent).'px;',"height"=>'20px;'));
                $content .= '<span class="exam_question_content_answer_mulichoice_percent_correct_label">'.round($percent,2).'%</span>';
                $content .='</div>';
                
                $percent = 100 - $percent;
                $content .= '<div class="exam_question_content_answer_mulichoice_result_incorrect" id="exam_question_content_answer_mulichoice_result_'.$item['answer_id'].'">';
                $content .= '<b>other choose</b></div>';
                $content .='<div class="exam_question_content_answer_mulichoice_percent_incorrect" id="exam_question_content_answer_mulichoice_percent_'.$item['answer_id'].'">';
                $content .= $this->view->htmlImage($this->view->baseUrl(). '/application/modules/Exam/externals/images/answer_incorrect.gif', $answer['incorrect_percent'], array('title' => $this->view->translate(""),"width"=>$percent.'px;',"height"=>'20px;'));
                $content .= '<span class="exam_question_content_answer_mulichoice_percent_incorrect_label">'.round($percent,2).'%</span>';
                $content .='</div>';
                
                $content .= '</div>';
                $content .='</li>';
                
        }
        if($viewstatic == true && $viewanswer == true && $explain == true && $number_choice != 1){
                $multichoice = substr($multichoice,0,-1);
                $value = $this->getKey($multichoice,$this->_answerlabel);
                $content .='<li class ="exam_question_content_answer_mulichoice">';
                $content .= '<div class="exam_question_content_answer_mulichoice_result" id="exam_question_content_answer_mulichoice_result_'.$item['answer_id'].'">';
                
                $percent = $group[$value] / $this->_exam->test_count;
                $percent = $percent * 100;
                
                $content .= '<div class="exam_question_content_answer_mulichoice_result_correct" id="exam_question_content_answer_mulichoice_result_'.$item['answer_id'].'">';
                $content .= '<b>'.$multichoice.'</b></div>';
                $content .='<div class="exam_question_content_answer_mulichoice_percent_correct" id="exam_question_content_answer_mulichoice_percent_'.$item['answer_id'].'">';
                $content .= $this->view->htmlImage($this->view->baseUrl() . '/application/modules/Exam/externals/images/answer_correct.gif', '', array('title' => $this->view->translate(""),"width"=>rount($percent),"height"=>'20px;'));
                $content .= '<span class="exam_question_content_answer_mulichoice_percent_correct_label">'.round($percent,2).'%</span>';
                $content .='</div>';
                
                $percent = 100 - $percent;
                $content .= '<div class="exam_question_content_answer_mulichoice_result_incorrect" id="exam_question_content_answer_mulichoice_result_'.$item['answer_id'].'">';
                $content .= '<b>other choose</b></div>';
                $content .='<div class="exam_question_content_answer_mulichoice_percent_incorrect" id="exam_question_content_answer_mulichoice_percent_'.$item['answer_id'].'">';
                $content .= $this->view->htmlImage($this->view->baseUrl() . '/application/modules/Exam/externals/images/answer_incorrect.gif', '', array('title' => $this->view->translate(""),"width"=>round($percent),"height"=>'20px;'));
                $content .= '<span class="exam_question_content_answer_mulichoice_percent_incorrect_label">'.round($percent,2).'%</span>';
                $content .='</div>';
                
                $content .= '</div>';
                $content .='</li>';
                
        }
        
        return $content;
    }
    
    public function getlabel($group,$labels){
        $answer_ids = explode(',',$group);
        $result = '';
        foreach($answer_ids as $id){
            if(!empty($id)) $result.= $labels[$id].',';
        }
        $result = substr($result,0,-1);
        return $result;
    }
    public function getKey($label,$labels){
        $answer_ids = explode(',',$label);
        $result = '';
        foreach($answer_ids as $id){
            foreach($labels as $k => $v){
                if( $id == $v) {
                    $result.= $k.',';
                    break;
                }
                
            }   
        }
        return $result;
    }
    public function getOtherValue($label,$labels){
        $total = 0;
        foreach($labels as $group => $value){
            if($group != $label){
                $total+=$value;
                }  
        }
        return $total;
    }
    
    public function renderJavascript(){
        $this->view->headScript()
        ->prependScript("
            window.addEvent('domready',function(){
                exam.test.showResult = ".intval($this->_isShowAnswer).";
                exam.test.finishTest = ".intval($this->_finishTest).";
                exam.test.initFormQuestion(".$this->_type.",".$this->_numberQuestionPerPage.");
                $('exam_form_test_next').addEvent('click',function(){
                    exam.test.showQuestion();
                });
            });
        ");
    }
    
    
}
?>